package com.heima.homeservicemanagementsystem.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.homeservicemanagementsystem.mapper.UserAddressMapper;
import com.heima.homeservicemanagementsystem.entity.UserAddress;
import com.heima.homeservicemanagementsystem.service.UserAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 地址(UserAddress)表服务实现类
 *
 * @author makejava
 * @since 2025-04-09 11:41:38
 */
@Slf4j
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements UserAddressService {


    @Override
    public List<UserAddress> getUserId(String loginIdAsString) {
        QueryWrapper<UserAddress> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", loginIdAsString);
        List<UserAddress> userAddresses = baseMapper.selectList(wrapper);
        log.info("用户信息:{}", userAddresses);

        return userAddresses;
    }

    @Override
    public List<UserAddress> getUserIdiSempty(UserAddress loginIdAsString) {
        String loginIdAsString1 = StpUtil.getLoginIdAsString();
        QueryWrapper<UserAddress> wrapper = new QueryWrapper<>();
        log.info("正价：{}", StringUtils.hasLength(loginIdAsString.getUserId()));

        if (StringUtils.hasLength(loginIdAsString.getUserId())) {
            wrapper.eq("user_id", loginIdAsString.getUserId());
        } else {
            wrapper.eq("user_id", loginIdAsString1);
        }

        wrapper.eq("is_default", "true");
        wrapper.ne("id", loginIdAsString.getId());
        List<UserAddress> userAddresses = baseMapper.selectList(wrapper);
        log.info("用为true:{}", userAddresses);

        return userAddresses;
    }
}

